<script setup>
import { ref } from 'vue'
import { dologin } from "@/api/login";
import { useRouter } from 'vue-router'
import { ElMessage } from "element-plus";

const loginForm = ref({
  username: '',
  password: ''
})

const router = useRouter();

const login = async () => {
  const res = await dologin(loginForm.value)
  if (res.code == 200) {
    const { username, id, password ,role} = res;
    localStorage.setItem("username", username)

    localStorage.setItem("password",password )
    //
    localStorage.setItem("id", id)
    localStorage.setItem("role", role)
    //role
    router.push('/home/homeIndex')
  } else {
    ElMessage.error(res.message)
  }
}
</script>

<template>
  <div class="login-container">
    <div class="login-card">
      <h1 class="title">预测信用卡欺诈系统</h1>
      <p class="subtitle">请登录以继续</p>

      <el-form class="form-container">
        <el-form-item label="用户名" class="form-item">
          <el-input v-model="loginForm.username" placeholder="请输入用户名" clearable></el-input>
        </el-form-item>

        <el-form-item label="密码" class="form-item">
          <el-input v-model="loginForm.password" placeholder="请输入密码" type="password" clearable></el-input>
        </el-form-item>

        <el-form-item class="form-item button-container">
          <el-button type="primary" @click="login" class="login-button">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<style scoped>
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background: linear-gradient(135deg, #74ebd5 0%, #ACB6E5 100%);
}

.login-card {
  background-color: white;
  padding: 40px;
  width: 400px;
  border-radius: 15px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  text-align: center;
}

.title {
  font-size: 24px;
  color: #333;
  font-weight: 700;
  margin-bottom: 10px;
}

.subtitle {
  font-size: 14px;
  color: #666;
  margin-bottom: 30px;
}

.form-container {
  width: 100%;
}

.form-item {
  margin-bottom: 20px;
}

.el-input {
  width: 100%;
}

.button-container {
  display: flex;
  justify-content: center;
}

.login-button {
  width: 100%;
  height: 40px;
  background-color: #409EFF;
  border-color: #409EFF;
  color: white;
  font-size: 16px;
  font-weight: bold;
  border-radius: 10px;
}

.login-button:hover {
  background-color: #66b1ff;
}

</style>
